package org.csu.mypetstore.service;

import org.csu.mypetstore.persistence.CartMapper;
import org.csu.mypetstore.domain.Cart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CartService {
    @Autowired
    CartMapper cartDAO;

    public void insertintocart(Cart cart ,String usrename){
        cartDAO.insertCart(cart,usrename);
    }
    public List<Cart> getCartByusername(String username){
        return cartDAO.getCartByusername(username);
    }
    public void deletecart_by_username(String username){
        cartDAO.deletecart(username);
    }

    public void Updatecart(String username,String itemid,Cart cart){
        cartDAO.Updatecart(username,itemid,cart.getQuantity(),cart.getTotal());
    }
    public void Delete_By_Username_and_Itemid(String username,String itemid){
        cartDAO.deletecartByusername_and_itemid(username,itemid);
    }
    public int isExit(String username,String itemid){
        if (cartDAO.isExist(username,itemid)!= null)
            return 1;
        else
            return 0;
    }
    public Cart getCart(String username,String Itemid){
        return cartDAO.getCartByusername2(username,Itemid);
    }
}
